class Solution {
public:
    int findUnsortedSubarray(vector<int>& nums) 
    {

       int right = 0;
       int left = 0;
       int maxnum = INT_MIN;
       int minnum = INT_MAX;
       //从左往右遍历寻找B区域的右端点
       for(int i  = 0;i<nums.size();i++)
       {
            if(nums[i]>=maxnum)
            {
                maxnum = nums[i];
            }
            else
            {
                right = i;//当前值是小于maxn的，是B区域的值
            }
       }
       //寻找B区域的左端点
       for(int i  = nums.size()-1;i>=0;i--)
       {
            if(nums[i]<=minnum)
            {
                minnum = nums[i];
            }
            else
            {
                left = i;
            }
       }
       if(left==0&&right == 0)
       {
            return 0;//处理特殊情况
       }
       return right-left+1;
    }
};